package clientGUI.userPanels.Controllers;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import college.Date;
import college.RequestTreatment;
import college.User;
import clientGUI.Controllers.Controller;
import clientserver.Client;
import clientserver.Packet;
/**
 * Controlls the supervisor GUIs and their various options.
 * @author G11
 *
 */
public class SupervisorController extends Controller {
	User connectedUser;
	RequestTreatment r;
	String currEvalname;
	int rid;
	
	/**
	 * Supervisor controller constructor.
	 * @param c - Client with which we are connected.
	 * @param id - the ID of the current request. (Request ID)
	 */
	public SupervisorController(Client c, int id){
		client = c;
		rid =id;
	}
	
	public void setUser(User s){
		connectedUser = s;
	}
	
	public String  getcurrEval()
	{
		
		RequestTreatment r= new RequestTreatment(client, rid);
		r.loadfromdb();
		currEvalname=r.getEvaluator();
			return currEvalname;

	}
	
	public ArrayList<String> getAllPosibleEvaluators()
	{
		List<User> u = User.GetUsersbyType(client, "ISE");
		
		ArrayList<String> evlogin;
	
		evlogin= new ArrayList<String>();
		Iterator<User> iter =u.iterator();
		 while(iter.hasNext())
		 {
			 evlogin.add(iter.next().getLogin());
		 
		 }
		return evlogin;
	}
	
	
	public void approvedEvaluator(){
		r = new RequestTreatment(client,rid);
		r.setcurrentstage(3);
		r.updatestageindb();
		}
	
	public void approvedEvaluationTimelimit() {
		r = new RequestTreatment(client,rid);
		r.setcurrentstage(4);
		r.updatestageindb();
	}
	public void disapproveEvaluationTimelimit(){
		r = new RequestTreatment(client,rid);
		r.setcurrentstage(3);
		r.updatestageindb();
	}
	
	public void approvedProcessLeaderTimelimit(){
		r = new RequestTreatment(client,rid);
		r.setcurrentstage(11);
		r.updatestageindb();
	}
	
	public Date getCurrentEndDate(){
		r = new RequestTreatment(client,rid);
		r.loadfromdb();
		System.out.println(r.getEndDate());
		Date dt = new Date(r.getEndDate());
			return dt;	
	}
	
	public void disapproveProcessLeaderTimelimit(){
		r = new RequestTreatment(client,rid);
		r.setcurrentstage(9);
		r.updatestageindb();
	}
	
	public Date getCurrentStartDate(){
		r = new RequestTreatment(client,rid);
		r.loadfromdb();
		Date dt = new Date(r.getStartDate());
			return dt;	
	}
	
	public void SetNewEvaluator( String neweval){
		currEvalname=neweval;
				String q = "UPDATE Request_details r SET r.responsibleactor = '"+currEvalname+"' WHERE r.id = '"+rid+"'";
		Packet p = new Packet(q);
		p.setUpdatePacket();
		client.SendPacketNowait(p);
		
	
		
	}
	
}
